﻿@using Resource;
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Expires" content="0">
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="Cache-control" content="no-cache">
    <meta http-equiv="Cache" content="no-cache">
    @{ await Html.RenderPartialAsync("/Views/Shared/_LayoutScript.cshtml"); }
    @{ await Html.RenderPartialAsync("/Views/Shared/_StyleCss.cshtml"); }
    <script type="text/javascript" src="~/lib/echarts/extension/dataTool.js" asp-append-version="true"></script>

    <link href="/css/ReportYield_Bak.css" rel="stylesheet" />
    <title>ReportYield</title>

    <style type="text/css">
        /* 遮罩层样式 */
        .modal {
            display: none;
            position: fixed;
            z-index: 1;
            left: 0;
            top: 0;
            width: 100%;
            height: 100%;
            overflow: auto;
            background-color: rgba(0,0,0,0.4);
        }

        /* 模态框内容样式 */
        .modal-content {
            background-color: #0d283f;
            border: 1px solid #007297;
            margin: 10% auto;
            padding: 20px;
            width: 25%;
        }

        .modal-title {
            font-weight: bold;
        }

        /* 关闭按钮样式 */
        .close {
            color: #fff;
            float: right;
            font-size: 28px;
            font-weight: bold;
        }

        /* 关闭按钮鼠标悬停样式 */
        .close:hover,
        .close:focus {
            color: #0BC4E9;
            text-decoration: none;
            cursor: pointer;
        }

        /*网栅格*/
        .form-flex {
            display: flex;
            flex-direction: column;
            gap: 0.1rem;
            font-size: 0.15rem;
        }

        .form-flex label {
            font-size: 0.15rem;
            font-weight: bold;
        }

        .form-flex .text {
            background-color: #0D283F;
            height: 100px;
            border: 1px solid #007297;
        }

        .form-flex input,
        .form-flex select,
        .form-flex textarea {
            border-radius: 5px;
            background-color: #0D283F;
            padding: 8px;
            border: 1px solid #007297;
        }

        .modaltable > tbody > tr > td > input,
        .modaltable > tbody > tr > td > select,
        .modaltable > tbody > tr > td > textarea {
            background-color: #0D283F;
            border: 1px solid #007297;
        }

        .form-flex button {
            /*background-color: #4CAF50;*/
            background-color: #07a3fd;
            color: white;
            padding: 0.06rem 0.2rem;
            border: none;
            border-radius: 4px;
            cursor: pointer;
        }

        .form-flex button:hover {
            /*background-color: #45a049;*/
            background-color: #2665f8;
        }


        .form-flex > select,
        .form-flex > input,
        .form-flex > textarea {
            background-color: #0D283F;
            border: 1px solid #007297;
        }

        .form-flex > select:hover,
        .form-flex > input:hover,
        .form-flex > textarea:hover {
            background-color: #2C3444;
        }

        button[type="submit"] {
            font-size: .16rem;
            padding: 0.41em 2em;
            text-align: center;
        }
        /*选项卡*/
        .tab {
            overflow: hidden;
            width: 100%;
            height: 0.6rem;
            padding-left: 0.1rem;
            padding-right: 0.2rem;
        }

        .tab button {
            background-color: inherit;
            float: left;
            border: none;
            outline: none;
            cursor: pointer;
            /*padding: 14px 16px;*/
            font-size: 0.16rem;
            padding: 0.14rem 0.16rem;
            transition: 0.3s;
            border-bottom: 2px solid #ffffff;
        }

        .tab button:hover {
            background-color: #384e61;
        }

        .tab button.active {
            color: #0080cc;
            border-bottom: 2px solid #0080cc;
        }

        .tabcontent {
            padding: 6px 12px;
            border-top: none;
            width: 100%;
            height: 4.6rem;
        }

        .remark {
            float: right;
        }

        .required {
            color: red;
            font-weight: bolder;
        }

        .tooltip > p {
            height: 0.25rem;
            line-height: 0.25rem;
        }

        .tooltip > p > label, .tooltip > p > span {
            color: #2C3444;
            height: 0.2rem;
            font-family: Arial;
            font-size: 0.14rem;
            font-weight: bold;
        }

        .tooltip > p > span {
            float: right;
        }
    </style>
</head>
<body class="fill-parent" style="overflow-y: hidden">
    <div class="main">
        <div class="header">
            <div class="header-left fl">
                <img src="/images/logo.png" class="scaled-image" />
            </div>
            <div class="btn">
                <spn>
                    <div id="query">
                        <div class="dropdown">
                            <button class="dropbtn">@Label.Language</button>
                            <div class="dropdown-content">
                                <a class="menudropdown" onclick="setLanguageCookie('@Const.CNLANGUAGE')">@Label.Chinese</a>
                                <a class="menudropdown" onclick="setLanguageCookie('@Const.USLANGUAGE')">@Label.English</a>
                            </div>
                        </div>
                        <button class="modalBtn dimension">@Label.Full</button>
                    </div>
                </spn>
            </div>
            <div class="header-center fl">
                <div class="header-title"></div>
                <div class="header-img"></div>
            </div>
            <div class="header-right fl" id="time"></div>
            <div class="header-bottom fl"></div>
        </div>
        <div class="center">
            <div class="center-left fl">
                <div class="left-top rightTop border">
                    <div class="title">
                        <label>@Html.Raw(Label.Process + @Label.Yield + @Label.Report)</label>
                    </div>
                    <div id="board" class="chart">
                        <div class="query">
                            <button class="btn btn-primary  btn-sm col-md-12" type="button" onclick="$('.modal').fadeIn();">@Html.Raw(Label.Query + @Label.Where)</button>
                            <button class="btn btn-primary  btn-sm col-md-12" type="button" onclick="$('.modal').fadeIn();">@Html.Raw(Label.Export)SN</button>
                        </div>
                        <div id="table-container">
                            <table class="DataSheet" border="1" style="width: 100%; height: 100%;">
                                <thead>
                                    <tr>
                                        <th>Station</th>
                                        <th>Input</th>
                                        <th>Output</th>
                                        <th>PrimeYield</th>
                                        <th>FinalYield</th>
                                        <th>FailureMode</th>
                                        <th>PrimeReject</th>
                                        <th>RetestPass</th>
                                        <th>PrimeRejectRate</th>
                                        <th>FinalRejectRate</th>
                                    </tr>
                                </thead>
                                <tbody id="yield_tbody"></tbody>
                                <tfoot>
                                    <tr>
                                        <th id="sum" colspan="3"></th>
                                        <th id="primeyield"></th>
                                        <th id="finalyield"></th>
                                        <th></th>
                                        <th></th>
                                        <th></th>
                                        <th></th>
                                        <th></th>
                                    </tr>
                                </tfoot>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
            <div class="center-cen fl">
                <div class="cen-top rightTop border">
                    <div class="title"><label>@Html.Raw(Label.Tests + Label.Item + Label.Fail + Label.Plato)</label></div>
                    <div id="chart1" class="chart"></div>
                </div>
                <div class="cen-bottom rightTop border">
                    <div class="title">CPK维护</div>
                    <div id="cpkgrid" class="chart">
                        <div class="cpk_table_id">
                            <table class="cpk_table">
                                <thead>
                                    <tr>
                                        <th>TESTER</th>
                                        <th>MEAN</th>
                                        <th>SIGMA</th>
                                        <th>CPK</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <tr>
                                        <td>Engine_66</td>
                                        <td contentEditable="true"></td>
                                        <td contentEditable="true"></td>
                                        <td contentEditable="true"></td>
                                    </tr>
                                    <tr>
                                        <td>Engine_67</td>
                                        <td contentEditable="true"></td>
                                        <td contentEditable="true"></td>
                                        <td contentEditable="true"></td>
                                    </tr>
                                    <tr>
                                        <td>Engine_68</td>
                                        <td contentEditable="true"></td>
                                        <td contentEditable="true"></td>
                                        <td contentEditable="true"></td>
                                    </tr>
                                    <tr>
                                        <td>Engine_69</td>
                                        <td contentEditable="true"></td>
                                        <td contentEditable="true"></td>
                                        <td contentEditable="true"></td>
                                    </tr>
                                    <tr>
                                        <td>Engine_70</td>
                                        <td contentEditable="true"></td>
                                        <td contentEditable="true"></td>
                                        <td contentEditable="true"></td>
                                    </tr>
                                    <tr>
                                        <td>Engine_71</td>
                                        <td contentEditable="true"></td>
                                        <td contentEditable="true"></td>
                                        <td contentEditable="true"></td>
                                    </tr>
                                    <tr>
                                        <td>Engine_72</td>
                                        <td contentEditable="true"></td>
                                        <td contentEditable="true"></td>
                                        <td contentEditable="true"></td>
                                    </tr>
                                    <tr class="">
                                        <td>Engine_73</td>
                                        <td contentEditable="true"></td>
                                        <td contentEditable="true"></td>
                                        <td contentEditable="true"></td>
                                    </tr>
                                    <tr>
                                        <td>Engine_74</td>
                                        <td contentEditable="true"></td>
                                        <td contentEditable="true"></td>
                                        <td contentEditable="true"></td>
                                    </tr>
                                    <tr>
                                        <td>Engine_75</td>
                                        <td contentEditable="true"></td>
                                        <td contentEditable="true"></td>
                                        <td contentEditable="true"></td>
                                    </tr>
                                    <tr>
                                        <td>Engine_76</td>
                                        <td contentEditable="true"></td>
                                        <td contentEditable="true"></td>
                                        <td contentEditable="true"></td>
                                    </tr>
                                    <tr>
                                        <td>Engine_77</td>
                                        <td contentEditable="true"></td>
                                        <td contentEditable="true"></td>
                                        <td contentEditable="true"></td>
                                    </tr>
                                    <tr>
                                        <td>Engine_77</td>
                                        <td contentEditable="true"></td>
                                        <td contentEditable="true"></td>
                                        <td contentEditable="true"></td>
                                    </tr>
                                    <tr>
                                        <td>Engine_77</td>
                                        <td contentEditable="true"></td>
                                        <td contentEditable="true"></td>
                                        <td contentEditable="true"></td>
                                    </tr>
                                    <tr>
                                        <td>Engine_77</td>
                                        <td contentEditable="true"></td>
                                        <td contentEditable="true"></td>
                                        <td contentEditable="true"></td>
                                    </tr>
                                    <tr>
                                        <td>Engine_77</td>
                                        <td contentEditable="true"></td>
                                        <td contentEditable="true"></td>
                                        <td contentEditable="true"></td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
            <div class="center-right fr">
                <div class="right-top rightTop border">
                    @*<div class="title"><label>设备不良率列表</label></div>*@
                    <div class="tab">
                        <button class="tablinks active" onclick="OpenTab(event,'right-top','Tab1',GetPrimeFailRate)">PrimeFailRate</button>
                        <button class="tablinks" onclick="OpenTab(event,'right-top','Tab1',GetFinalFailRate)">FinalFailRate</button>
                    </div>
                    <div id="Tab1" class="chart" style="padding: 0rem 0.2rem;">
                        <div class="cpk_table_id">
                            @*<table class="cpk_table">
                                    <thead>
                                        <tr>
                                            <th>TESTER</th>
                                            <th>INPUT </th>
                                            <th>PASS</th>
                                            <th>FAIL</th>
                                            <th>FAILURE</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <tr>
                                            <td>Engine_66</td>
                                            <td>66</td>
                                            <td>62</td>
                                            <td>4</td>
                                            <td>(4/66)0.0606 </td>
                                        </tr>
                                        <tr>
                                            <td>Engine_67</td>
                                            <td>66</td>
                                            <td>62</td>
                                            <td>4</td>
                                            <td>(4/66)0.0606 </td>
                                        </tr>
                                        <tr>
                                            <td>Engine_68</td>
                                            <td>66</td>
                                            <td>62</td>
                                            <td>4</td>
                                            <td>(4/66)0.0606 </td>
                                        </tr>
                                        <tr>
                                            <td>Engine_69</td>
                                            <td>66</td>
                                            <td>62</td>
                                            <td>4</td>
                                            <td>(4/66)0.0606 </td>
                                        </tr>
                                        <tr>
                                            <td>Engine_70</td>
                                            <td>66</td>
                                            <td>62</td>
                                            <td>4</td>
                                            <td>(4/66)0.0606 </td>
                                        </tr>
                                        <tr>
                                            <td>Engine_71</td>
                                            <td>66</td>
                                            <td>62</td>
                                            <td>4</td>
                                            <td>(4/66)0.0606 </td>
                                        </tr>
                                        <tr>
                                            <td>Engine_72</td>
                                            <td>66</td>
                                            <td>62</td>
                                            <td>4</td>
                                            <td>(4/66)0.0606 </td>
                                        </tr>
                                        <tr>
                                            <td>Engine_73</td>
                                            <td>66</td>
                                            <td>62</td>
                                            <td>4</td>
                                            <td>(4/66)0.0606 </td>
                                        </tr>
                                        <tr>
                                            <td>Engine_74</td>
                                            <td>66</td>
                                            <td>62</td>
                                            <td>4</td>
                                            <td>(4/66)0.0606 </td>
                                        </tr>
                                        <tr>
                                            <td>Engine_75</td>
                                            <td>66</td>
                                            <td>62</td>
                                            <td>4</td>
                                            <td>(4/66)0.0606 </td>
                                        </tr>
                                        <tr>
                                            <td>Engine_76</td>
                                            <td>66</td>
                                            <td>62</td>
                                            <td>4</td>
                                            <td>(4/66)0.0606 </td>
                                        </tr>
                                        <tr>
                                            <td>Engine_77</td>
                                            <td>66</td>
                                            <td>62</td>
                                            <td>4</td>
                                            <td>(4/66)0.0606 </td>
                                        </tr>
                                        <tr>
                                            <td>Engine_77</td>
                                            <td>66</td>
                                            <td>62</td>
                                            <td>4</td>
                                            <td>(4/66)0.0606 </td>
                                        </tr>
                                        <tr>
                                            <td>Engine_77</td>
                                            <td>66</td>
                                            <td>62</td>
                                            <td>4</td>
                                            <td>(4/66)0.0606 </td>
                                        </tr>
                                        <tr>
                                            <td>Engine_77</td>
                                            <td>66</td>
                                            <td>62</td>
                                            <td>4</td>
                                            <td>(4/66)0.0606 </td>
                                        </tr>
                                        <tr>
                                            <td>Engine_77</td>
                                            <td>66</td>
                                            <td>62</td>
                                            <td>4</td>
                                            <td>(4/66)0.0606 </td>
                                        </tr>
                                    </tbody>
                                    <tfoot>
                                        <tr>
                                            <th>总计</th>
                                            <td>66</td>
                                            <td>62</td>
                                            <td>4</td>
                                            <td>(4/66)0.0606 </td>
                                        </tr>
                                    </tfoot>
                                </table>*@
                        </div>
                    </div>
                </div>
                <div class="right-bottom rightTop border">
                    @*<div class="title">箱线图</div>*@
                    <div class="tab">
                        <button class="tablinks active" onclick="OpenTab(event,'right-bottom','Tab2',GetBoxPlot)">2/1</button>
                        <button class="tablinks" onclick="OpenTab(event,'right-bottom','Tab2',GetBoxPlot)">2/3</button>
                        <button class="tablinks" onclick="OpenTab(event,'right-bottom','Tab2',GetBoxPlot)">2/4</button>
                        <button class="tablinks" onclick="OpenTab(event,'right-bottom','Tab2',GetBoxPlot)">2/5</button>
                        <button class="tablinks" onclick="OpenTab(event,'right-bottom','Tab2',GetBoxPlot)">2/6</button>
                        <button class="tablinks" onclick="OpenTab(event,'right-bottom','Tab2',GetBoxPlot)">2/7</button>
                        <button class="tablinks" onclick="OpenTab(event,'right-bottom','Tab2',GetBoxPlot)">2/8</button>
                    </div>
                    <div id="Tab2" class="chart"></div>
                </div>
            </div>
        </div>
    </div>
    <!-- 模态框 -->
    <div class="modal">
        <div class="modal-content family">
            <span class="close" onclick="ModalClose('modal')">×</span>
            <p id="Item" class="modal-title">@Html.Raw(Label.Query + Label.Where)</p>
            <br>
            <div class="form-flex">
                <p><label for="Projectcode">ProjectCode:</label><span class="remark required">*</span></p>
                <select id="cmb_proj_code" name="Projectcode" placeholder="select Projectcode">
                    <option value="">@Label.PleaseSelect</option>
                </select>
                <p><label for="Processes">Processes:</label><span class="remark">*</span></p>
                <select id="cmb_processes" name="Projectcode" placeholder="select Processes">
                    <option value="">@Label.PleaseSelect</option>
                </select>
                <p><label for="TestGrade">TestGrade:</label><span class="remark">*</span></p>
                <select id="cmb_testgrade" name="TestGrade" placeholder="select TestGrade">
                    <option value="">@Label.PleaseSelect</option>
                </select>
                <p><label for="TestItem">TestItem:</label><span class="remark">*</span></p>
                <select id="cmb_testitem" name="TestItem" placeholder="select TestItem">
                    <option value="">@Label.PleaseSelect</option>
                </select>
                <p>
                    <span class="exampleInputProject tle">@Html.Raw(Label.Time):</span>
                    <input type="date" id="startdate" name="startdate" placeholder="@Label.Start@Label.Time">
                    <span class="exampleInputProject tle">@Label.To</span>
                    <input type="date" id="enddate" name="enddate" placeholder="@Label.Start@Label.End">
                    <span class="remark required">*</span>
                </p>
                <button type="submit" style="font-weight: bold; height:0.5rem;" onclick="Getdata()">@Html.Raw(Label.Query)</button>
            </div>
        </div>
    </div>

    <script type="text/javascript">
        $(document).ready(function () {
            $('#startdate').on('change', function () {
                $('#enddate').val('');
                var startDate = new Date($(this).val());
                var endDate = new Date($('#enddate').val());
                $('#enddate').attr('min', $(this).val());
                if (endDate < startDate) {
                    $('#enddate').val($(this).val());
                }
            });
            $('#enddate').on('change', function () {
                var startDate = new Date($('#startdate').val());
                var endDate = new Date($(this).val());
                var maxDate = new Date(startDate);
                maxDate.setDate(maxDate.getDate() + 7);
                if (endDate > maxDate) {
                    $('#enddate').val('');
                    alert('查询范围不能超过7天');
                } else {
                    $('#startdate').attr('max', $(this).val());
                    if (startDate > endDate) {
                        $('#startdate').val($(this).val());
                    }
                }
            });

            var whei = $(window).width()
            $("html").css({ fontSize: whei / 22 });
            $(window).resize(function () {
                var whei = $(window).width();
                $("html").css({ fontSize: whei / 22 })
            });

            function numberToUpperCase(number) {
                var uppercaseMonths = ['一月', '二月', '三月', '四月', '五月', '六月','七月', '八月', '九月', '十月', '十一月', '十二月'];
                return uppercaseMonths[number - 1];
            }
            var myDate = new Date();
            var result = numberToUpperCase(myDate.getMonth() + 1);
            $('.header-title').html("测试项趋势图表");
            function getTime() {
                var myDate = new Date();
                var myYear = myDate.getFullYear(); //年
                var myMonth = myDate.getMonth() + 1; //月
                var myToday = myDate.getDate(); //日
                var myDay = myDate.getDay(); //星期
                var myHour = myDate.getHours(); //小时
                var myMinute = myDate.getMinutes(); //分钟
                var mySecond = myDate.getSeconds(); //秒数
                var week = ['@Label.Sunday', '@Label.Monday', '@Label.Tuesday', '@Label.Wednesday', '@Label.Thursday', '@Label.Friday', '@Label.Saturday'];
                var nowTime;

                nowTime = myYear + '-' + fillZero(myMonth) + '-' + fillZero(myToday) + '&nbsp;&nbsp;' + fillZero(myHour) + ':' + fillZero(myMinute) + ':' + fillZero(mySecond) + '&nbsp;&nbsp;' + week[myDay] + '&nbsp;&nbsp;';
                $('#time').html(nowTime);
            };
            function fillZero(str) {
                var realNum;
                if (str < 10) {
                    realNum = '0' + str;
                } else {
                    realNum = str;
                }
                return realNum;
            }
            setInterval(getTime, 1000);

            //设置全屏
            $('.dimension').on('click', function (e) {
                var element = document.documentElement;
                if ($(".dimension").text() == "@Html.Raw(Label.Full)") {
                    //判断浏览器设备类型
                    if (element.requestFullscreen) {
                        element.requestFullscreen();
                    } else if (element.mozRequestFullScreen) {       //兼容火狐
                        element.mozRequestFullScreen();
                    } else if (element.webkitRequestFullscreen) {    //兼容谷歌
                        element.webkitRequestFullscreen();
                    } else if (element.msRequestFullscreen) {        //兼容IE
                        element.msRequestFullscreen();
                    }
                    $(".dimension").text("@Html.Raw(Label.Exit+Label.Full)");
                } else {
                    if (document.exitFullscreen) {
                        document.exitFullscreen();
                    } else if (document.mozCancelFullScreen) {
                        document.mozCancelFullScreen();
                    } else if (document.webkitCancelFullScreen) {
                        document.webkitCancelFullScreen();
                    } else if (document.msExitFullscreen) {
                        document.msExitFullscreen();
                    }
                    $(".dimension").text("@Html.Raw(Label.Full)");
                }
            });
        });

        //初始化图表
        var memachinetype;
        var chartIds = ['chart1', 'chart2'];
        function echartsautomatic() {
            var charts = [];
            chartIds.forEach(function (chartId) {
                var chart = echarts.init(document.getElementById(chartId));
                charts.push(chart);
            });
            window.onresize = function () {
                charts.forEach(function (chart) {
                    chart.resize();
                });
            };
        }

        function ModalClose(modalname) {
            var close = document.getElementsByClassName(modalname);
            $(close).fadeOut();
        }

        //Tab页签定时切换
        var Tabtimer;
        function TabInterval() {
            clearInterval(Tabtimer);
            //每隔5m执行一次
            Tabtimer = setInterval(function () {
                Getdata();
                echartsautomatic();
            }, 2 * 60 * 1000);
        }

        $(function () {
            var projectsele = $("#cmb_proj_code");
            loadData(projectsele, api + '/Dashboard/GetComProjCode');
            function loadData(selectElement, url) {
                $.ajax({
                    type: "POST",
                    url: url,
                    dataType: "json",
                    success: function (data) {
                        selectdata = data.ReturnData;
                        selectElement.empty();
                        if (selectdata.length <= 0) {
                            var option = "<option>@Html.Raw(Label.No+Label.Correlation+Label.Data)</option>";
                            selectElement.append(option);
                            return;
                        }
                        selectElement.append("<option value='-1'>@Html.Raw(Label.PleaseSelect)...</option>");
                        $.each(selectdata, function (key, value) {
                            selectElement.append($('<option>', {
                                value: value.text,
                                text: value.value
                            }));
                        });
                    }
                });
            }
        });

        function stateselected() {
            var state = false;
            if ($('#cmb_proj_code').prop('selectedIndex') > 0 && $("#startdate").val() && $("#enddate").val()) {
                state = true;
            }
            return state;
        }

        /*Tab切换*/
        function OpenTab(evt, panle, id, echar_name, itemindex = -1) {
            var i, tablinks;
            tablinks = document.getElementsByClassName(panle)[0].getElementsByClassName("tablinks");
            for (i = 0; i < tablinks.length; i++) {
                tablinks[i].className = tablinks[i].className.replace("active", "");
            }
            evt.currentTarget.className += " active";
            //注销eacharts
            let chart = echarts.init(document.getElementById(id));
            chart.dispose();
            /*TabItem 页签滚动*/
            if (itemindex > -1) {
                var listContainer = document.getElementById("listContainer");
                var listItem = listContainer.children[itemindex];
                var scrollContainer = document.getElementById("scrollContainer");
                // 计算要滚动的距离
                var scrollLeft = listItem.offsetLeft - scrollContainer.offsetLeft;
                // 滚动到指定位置
                //scrollContainer.scrollLeft = scrollLeft;
                scrollContainer.scrollTo({
                    left: scrollLeft,
                    behavior: "smooth",
                });
            }
            /*委托事件*/
            if (!memachinetype) {
                echar_name(id);
            }
            else {
                GetToDayMeMachine(id);
            }
            echartsautomatic();
        }

        var chartdata;
        var Getdata = function () {
            if (stateselected()) {
                //boarddata();
                //echartsautomatic();
                //TabInterval();
            }
        }

        var GetPrimeFailRate = function (id) {
            var html = `<div class="cpk_table_id"><table class="cpk_table"><thead><tr><th>TESTER</th><th>INPUT </th><th>PASS</th><th>FAIL</th><th>FAILURE</th></tr></thead><tbody><tr><td>Engine_77</td><td>77</td><td>72</td><td>4</td><td>(4/77)0.0707 </td></tr><tr><td>Engine_77</td><td>77</td><td>72</td><td>4</td><td>(4/77)0.0707 </td></tr><tr><td>Engine_78</td><td>77</td><td>72</td><td>4</td><td>(4/77)0.0707 </td></tr><tr><td>Engine_79</td><td>77</td><td>72</td><td>4</td><td>(4/77)0.0707 </td></tr><tr><td>Engine_70</td><td>77</td><td>72</td><td>4</td><td>(4/77)0.0707 </td></tr><tr><td>Engine_71</td><td>77</td><td>72</td><td>4</td><td>(4/77)0.0707 </td></tr><tr><td>Engine_72</td><td>77</td><td>72</td><td>4</td><td>(4/77)0.0707 </td></tr><tr><td>Engine_73</td><td>77</td><td>72</td><td>4</td><td>(4/77)0.0707 </td></tr><tr><td>Engine_74</td><td>77</td><td>72</td><td>4</td><td>(4/77)0.0707 </td></tr><tr><td>Engine_75</td><td>77</td><td>72</td><td>4</td><td>(4/77)0.0707 </td></tr><tr><td>Engine_77</td><td>77</td><td>72</td><td>4</td><td>(4/77)0.0707 </td></tr><tr><td>Engine_77</td><td>77</td><td>72</td><td>4</td><td>(4/77)0.0707 </td></tr><tr><td>Engine_77</td><td>77</td><td>72</td><td>4</td><td>(4/77)0.0707 </td></tr><tr><td>Engine_77</td><td>77</td><td>72</td><td>4</td><td>(4/77)0.0707 </td></tr><tr><td>Engine_77</td><td>77</td><td>72</td><td>4</td><td>(4/77)0.0707 </td></tr><tr><td>Engine_77</td><td>77</td><td>72</td><td>4</td><td>(4/77)0.0707 </td></tr></tbody><tfoot><tr><th>总计</th><td>77</td><td>72</td><td>4</td><td>(4/77)0.0707 </td></tr></tfoot></table></div>`;
            $('#' + id).html(html);
        }

        var GetFinalFailRate = function (id) {
            var html = `<div class="cpk_table_id"><table class="cpk_table"><thead><tr><th>TESTER</th><th>INPUT </th><th>PASS</th><th>FAIL</th><th>FAILURE</th></tr></thead><tbody><tr><td>Engine_66</td><td>66</td><td>62</td><td>4</td><td>(4/66)0.0606 </td></tr><tr><td>Engine_67</td><td>66</td><td>62</td><td>4</td><td>(4/66)0.0606 </td></tr><tr><td>Engine_68</td><td>66</td><td>62</td><td>4</td><td>(4/66)0.0606 </td></tr><tr><td>Engine_69</td><td>66</td><td>62</td><td>4</td><td>(4/66)0.0606 </td></tr><tr><td>Engine_70</td><td>66</td><td>62</td><td>4</td><td>(4/66)0.0606 </td></tr><tr><td>Engine_71</td><td>66</td><td>62</td><td>4</td><td>(4/66)0.0606 </td></tr><tr><td>Engine_72</td><td>66</td><td>62</td><td>4</td><td>(4/66)0.0606 </td></tr><tr><td>Engine_73</td><td>66</td><td>62</td><td>4</td><td>(4/66)0.0606 </td></tr><tr><td>Engine_74</td><td>66</td><td>62</td><td>4</td><td>(4/66)0.0606 </td></tr><tr><td>Engine_75</td><td>66</td><td>62</td><td>4</td><td>(4/66)0.0606 </td></tr><tr><td>Engine_76</td><td>66</td><td>62</td><td>4</td><td>(4/66)0.0606 </td></tr><tr><td>Engine_77</td><td>66</td><td>62</td><td>4</td><td>(4/66)0.0606 </td></tr><tr><td>Engine_77</td><td>66</td><td>62</td><td>4</td><td>(4/66)0.0606 </td></tr><tr><td>Engine_77</td><td>66</td><td>62</td><td>4</td><td>(4/66)0.0606 </td></tr><tr><td>Engine_77</td><td>66</td><td>62</td><td>4</td><td>(4/66)0.0606 </td></tr><tr><td>Engine_77</td><td>66</td><td>62</td><td>4</td><td>(4/66)0.0606 </td></tr></tbody><tfoot><tr><th>总计</th><td>66</td><td>62</td><td>4</td><td>(4/66)0.0606 </td></tr></tfoot></table></div>`;
            $('#' + id).html(html);
        }

        var GetBoxPlot = function (id) {
            BoxPlotChart(id);
        }

        var BoxPlotChart = function (id) {
            // 基于准备好的dom，初始化echarts实例
            let myChart = echarts.init(document.getElementById(id));
            // echarts.dataTool.prepareBoxplotData--处理盒须图需要的数据格式
            let ydata = echarts.dataTool.prepareBoxplotData([
                [132.43, 106.84, 123.98, 117.85, 121.02],
                [133.67, 106.24, 123.98, 117.85, 121.02],
                [135.43, 106.94, 123.98, 117.85, 121.02],
                [132.43, 106.84, 128.98, 117.85, 121.02],
                [137.43, 106.84, 123.98, 117.85, 121.02],
                [132.43, 109.84, 123.98, 115.85, 121.02],
                [135.43, 106.94, 123.98, 117.85, 121.02],
                [132.43, 116.84, 123.98, 117.85, 131.02],
                [133.67, 106.24, 123.98, 117.85, 121.02],
                [132.43, 116.84, 123.98, 117.85, 131.02],
                [135.43, 106.94, 123.98, 117.85, 121.02],
                [132.43, 116.84, 123.98, 117.85, 131.02],
            ], {
                boundIQR: 'none',//是否需要计算
            })
            let option = {
                title: { show: false },
                textStyle: {
                    color: 'red',
                    fontSize: '0.16rem'
                },
                tooltip: {
                    show: true,
                    trigger: 'axis',
                    textStyle: {
                        color: 'red',
                        fontSize: '0.13rem',
                        align: 'left'
                    },
                    axisPointer: {
                        type: 'line',
                        lineStyle: {
                            width: 1,
                            color: "#84afaa",
                            type: "dashed"
                        }
                    },
                    formatter: function (params) {
                        var txt = `
                        <div class="tooltip">
                            <p><label>${params[0].name}</label></p>
                            <p><label>${params[0].marker}上限值(Max):</label><span>${params[0].data[5]}</span></p>
                            <p><label>${params[0].marker}Q3(上四分位数):</label><span>${params[0].data[4]}</span></p>
                            <p><label>${params[0].marker}Q2(中位数):</label><span>${params[0].data[3]}</span></p>
                            <p><label>${params[0].marker}Q1(下四分位数):</label><span>${params[0].data[2]}</span></p>
                            <p><label>${params[0].marker}下限值(Min):</label><span>${params[0].data[1]}</span</p>
                            <p><label>${params[1].marker}平均值:</label><span>${params[1].value}</span></p>
                        </div>`;
                        return txt;
                    }
                },
                grid: {
                    top: '5%',
                    right: '2%',
                    bottom: '5%',
                    width: '98%',
                    containLabel: true
                },
                xAxis: {
                    type: 'category',
                    boundaryGap: true,
                    nameGap: 30,
                    nameLocation: "middle",
                    axisLabel: {
                        show: true,
                        interval: 0,
                        rotate: 45,
                        color: '#fff',
                        fontSize: '0.14rem'
                    },
                    splitArea: {
                        show: false,
                    },
                    splitLine: {
                        show: false,
                    },
                    axisTick: {
                        show: false,
                    },
                    axisLine: {
                        show: false,
                    },
                    data: ["Engine_66", "Engine_67", "Engine_68", "Engine_69", "Engine_70", "Engine_71", "Engine_72", "Engine_73", "Engine_74", "Engine_75", "Engine_76", "Engine_77"]
                },
                yAxis: [{
                    type: 'value',
                    axisLabel: {
                        textStyle: {
                            color: '#fff',
                            fontSize: '0.15rem'
                        }
                    },
                    splitArea: {
                        show: false,
                    },
                    axisTick: {
                        show: false,
                    },
                    axisLine: {
                        show: false,
                    },
                }, {
                    type: 'value',
                    name: `{legend|} {value|平均值}`,
                    show: false,
                    axisLabel: {
                        show: false,
                    },
                    axisTick: {
                        show: false,
                    },
                    axisLine: {
                        show: false,
                    },
                    axisLine: {
                        show: false,
                    },
                    nameTextStyle: {
                        rich: {
                            legend: {
                                width: 50,
                                height: 2,
                                backgroundColor: "#fbd173"
                            }
                        }
                    }
                },],
                series: [
                    {
                        type: 'boxplot',
                        itemStyle:{
                            borderColor: "#45c7ea",
                            borderWidth: 1.2,
                            color: "#0080cc"
                        },
                        data: ydata.boxData
                    },
                    {
                        name: '平均值',
                        type: 'line',
                        color: "#fbd173",
                        yAxisIndex: 1,
                        showSymbol: false,
                        data: [120.77, 120.26, 120.22, 120.38, 119.9, 120.26, 120.22, 120.38, 121.79, 120.65]
                    }
                ]
            };
            option && myChart.setOption(option);
            window.addEventListener('resize', function () {
                myChart.resize();
            });

        }
        //报表
        var boarddata = function () {
            var pam = {};
            pam.product_code = $('#cmb_proj_code').val();
            pam.process = $('#cmb_process_code').val();
            pam.start = $("#startdate").val()
            pam.end = $("#enddate").val()
            if (pam.product_code !== "-1" && pam.process !== "-1") {
                $.ajax({
                    type: "POST",
                    url: "/Report/Getdata",
                    data: pam,
                    dataType: "json",
                    success: function (data) {
                        chartdata = data;
                        primeyieldChart();
                        platoChart();
                        var table = "";
                        var primeyield, finalyield;
                        for (var i = 0; i < data.yield.length; i++) {
                            var zebracro = i % 2;
                            if (data.yield[i].row_id && parseInt(data.yield[i].row_id) > 0) {
                                table += '<tr ' + (zebracro == 0 ? 'class="zebracro"' : '') + '>'
                                    + '<td class="tabletd" rowspan=' + data.yield[i].rowspan + '>' + data.yield[i].process_name + '</td>'
                                    + '<td class="tabletd" rowspan=' + data.yield[i].rowspan + '>' + data.yield[i].input_qty + '</td>'
                                    + '<td class="tabletd" rowspan=' + data.yield[i].rowspan + '>' + data.yield[i].output_qty + '</td>'
                                    + '<td class="tabletd" rowspan=' + data.yield[i].rowspan + '>' + data.yield[i].prime_yield + '</td>'
                                    + '<td class="tabletd" rowspan=' + data.yield[i].rowspan + '>' + data.yield[i].final_yield + '</td>'
                                    + '<td>' + data.yield[i].category + '</td>'
                                    + '<td class="tabletd">' + data.yield[i].prime_reject + '</td>'
                                    + '<td class="tabletd">' + data.yield[i].retest_pass + '</td>'
                                    + '<td class="tabletd">' + data.yield[i].prime_reject_yield + '</td>'
                                    + '<td class="tabletd">' + data.yield[i].retest_pass_yield + '</td>'
                                    + '</tr>';
                                if (!(primeyield)) {
                                    primeyield = parseFloat(data.yield[i].prime_yield.substring(0, data.yield[i].prime_yield.indexOf("%"))) / 100;
                                }
                                else {
                                    primeyield = primeyield * parseFloat(data.yield[i].prime_yield.substring(0, data.yield[i].prime_yield.indexOf("%"))) / 100;
                                }
                                if (!(finalyield)) {
                                    finalyield = parseFloat(data.yield[i].final_yield.substring(0, data.yield[i].final_yield.indexOf("%"))) / 100;
                                }
                                else {
                                    finalyield = finalyield * parseFloat(data.yield[i].final_yield.substring(0, data.yield[i].final_yield.indexOf("%"))) / 100;
                                }
                            }
                            else {
                                table += '<tr ' + (zebracro == 0 ? 'class="zebracro"' : '') + '>'
                                    + '<td>' + data.yield[i].category + '</td>'
                                    + '<td class="tabletd">' + data.yield[i].prime_reject + '</td>'
                                    + '<td class="tabletd">' + data.yield[i].retest_pass + '</td>'
                                    + '<td class="tabletd">' + data.yield[i].prime_reject_yield + '</td>'
                                    + '<td class="tabletd">' + data.yield[i].retest_pass_yield + '</td>'
                                    + '</tr>';
                            }
                        }
                        $('#yield_tbody').html(table);
                        $("#sum").text("@Html.Raw(Label.Summary)");
                        $('#primeyield').html(parseFloat((primeyield * 100).toFixed(2)) + "%");
                        $('#finalyield').html(parseFloat((finalyield * 100).toFixed(2)) + "%");
                    }
                });
            }
        };

        //chart
        var  primeyield_optionloop;
        function primeyieldChart() {
            var colorList = ['#338AF6', '#78C77D', '#F4D35F', '#435184', '#8C67DE', '#6BC8CA', '#0AAF9F', '#E89589', '#16A085', '#4A235A', '#C39BD3 ', '#F9E79F', '#BA4A00', '#ECF0F1', '#616A6B', '#EAF2F8', '#4A235A', '#3498DB'];
            var chart = document.getElementById("chart1");
            var myChart = echarts.init(chart);
            var machineitem = [];
            var itemvaule = [];
            var itemcolor = [];
            var linevaule = [];
            if (chartdata) {
                for (var i = 0; i < chartdata.yieldmachine.length; i++) {
                    machineitem.push(chartdata.yieldmachine[i].tester);
                    itemvaule.push(chartdata.yieldmachine[i].machine_prime_yield);
                    itemcolor.push(colorList[parseInt(chartdata.yieldmachine[i].sort)]);
                    linevaule.push(parseInt(chartdata.yieldmachine[i].prime_reject));

                }
            };
            var linemax = Math.max.apply(null, linevaule);
            option = {
                textStyle: {
                    color: '#fff',
                    fontSize: '0.14rem'
                },
                tooltip: {
                    trigger: 'axis',
                    axisPointer: {
                        type: 'shadow'
                    }
                },
                grid: {
                    top: '10%',
                    left: '10%',
                    right: '3%',
                    bottom: '28%',
                    width: '87%'
                },
                xAxis: [
                    {
                        type: 'category',
                        data: machineitem,
                        axisTick: {
                            alignWithLabel: true
                        },
                        axisLabel: {
                            show: true,
                            interval: 0,
                            rotate: 45,
                            textStyle: {
                                color: 'white',
                                fontSize: '0.12rem'
                            }
                        }
                    }
                ],
                yAxis: [
                    {
                        type: 'value',
                        //name: 'PrimeYield',
                        min: 0,
                        max: 100,
                        interval: 20,
                        axisLabel: {
                            show: true,
                            formatter: '{value} %',
                            textStyle: {
                                color: 'white',
                                fontSize: '0.12rem'
                            }
                        }
                    },
                    {
                        type: 'value',
                        min: 0,
                        max: 100,
                        interval: 20,
                        axisLabel: {
                            show: false,
                            formatter: '{value}',
                            textStyle: {
                                color: 'white',
                                fontSize: '0.12rem'
                            }
                        }
                    }
                ],
                series: [
                    {
                        name: 'PrimeYield',
                        type: 'bar',
                        barWidth: '50%',
                        itemStyle: {
                            normal: {
                                color: function (params) {
                                    var colorList = itemcolor;
                                    return colorList[params.dataIndex]
                                }
                            }
                        },
                        data: itemvaule,
                        tooltip: {
                            valueFormatter: function (value) {
                                return value + ' %';
                            }
                        }
                    },
                    {
                        name: 'PrimeRejectQty',
                        type: 'line',
                        yAxisIndex: 1,
                        itemStyle: {
                            color: '#FC8452',
                            Width: 3.5
                        },
                        lineStyle: {
                            normal: {
                                color: '#FC8452'
                            }
                        },
                        data: linevaule
                    }
                ]
            };
            myChart.setOption(option);
            if (primeyield_optionloop) {
                primeyield_optionloop.clearLoop();
            }
            primeyield_optionloop = tools.loopShowTooltip(echarts.init(chart), option, { loopSeries: true });
        };

        var plato_optionloop;
        function platoChart() {
            var chart = document.getElementById("chart2");
            var myChart = echarts.init(chart);
            var item = [];
            var itemvaule = [];
            var linevaule = [];
            var lastvaule;
            if (chartdata) {
                for (var i = 0; i < chartdata.yieldsummary.length; i++) {
                    item.push(chartdata.yieldsummary[i].category);
                    itemvaule.push(chartdata.yieldsummary[i].prime_reject_yield);
                    if (i == 0) {
                        lastvaule = chartdata.yieldsummary[i].average_yield;
                        linevaule.push(chartdata.yieldsummary[i].average_yield);
                    } else {
                        lastvaule = lastvaule + chartdata.yieldsummary[i].average_yield;
                        linevaule.push(lastvaule.toFixed(2));
                    }
                }
            };
            var itemvaulemax = Math.max.apply(null, itemvaule);
            option = {
                textStyle: {
                    color: '#fff',
                    fontSize: '0.14rem'
                },
                tooltip: {
                    trigger: 'axis',
                    axisPointer: {
                        type: 'cross',
                        crossStyle: {
                            color: 'white'
                        }
                    }
                },
                grid: {
                    top: '10%',
                    left: '10%',
                    right: '10%',
                    bottom: '30%',
                    width: '80%'
                },
                xAxis: [
                    {
                        type: 'category',
                        data: item,
                        axisLabel: {
                            show: true,
                            interval: 0,
                            rotate: 45,
                            textStyle: {
                                color: 'white',
                                fontSize: '0.12rem'
                            }
                        },
                        axisPointer: {
                            type: 'shadow'
                        }
                    }
                ],
                yAxis: [
                    {
                        type: 'value',
                        min: 0,
                        max: Math.ceil(itemvaulemax),
                        interval: Math.ceil(itemvaulemax) / 5,
                        axisLabel: {
                            show: true,
                            formatter: '{value} %',
                            textStyle: {
                                color: 'white',
                                fontSize: '0.12rem'
                            }
                        }
                    },
                    {
                        type: 'value',
                        min: 0,
                        max: 100,
                        interval: 20,
                        axisLabel: {
                            show: true,
                            formatter: '{value} %',
                            textStyle: {
                                color: 'white',
                                fontSize: '0.12rem'
                            }
                        }
                    }
                ],
                series: [
                    {
                        name: 'Failure Rate',
                        type: 'bar',
                        tooltip: {
                            valueFormatter: function (value) {
                                return value + ' %';
                            }
                        },
                        data: itemvaule
                    },
                    {
                        name: 'Proportion',
                        type: 'line',
                        yAxisIndex: 1,
                        tooltip: {
                            valueFormatter: function (value) {
                                return value + ' %';
                            }
                        },
                        data: linevaule
                    }
                ]
            };
            myChart.setOption(option);
            if (plato_optionloop) {
                plato_optionloop.clearLoop();
            }
            plato_optionloop = tools.loopShowTooltip(echarts.init(chart), option, {loopSeries: true});
        };
    </script>
</body>
</html>
